package main

import (
	"net"
	"fmt"
)

func main(){
	//创建监听端口
	listener,err:=net.Listen("tcp","127.0.0.1")
	if err != nil{
		fmt.Println("listen init failed,err=",err)
		return
	}

	defer listener.Close()

	//等待用户连接
	conn ,err := listener.Accept()
	if err != nil{
		fmt.Println("accept init failed,err=",err)
		return
	}

	//读取用户数据
	buf := make([]byte,1024)

	n,err := conn.Read(buf)
	if err != nil{
		fmt.Println("err=",err)
		return
	}
	fmt.Println("buf=",string(buf[:n]))
	defer conn.Close()
}
